import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},
{
  path: '/404',
  component: () => import('@/views/404'),
  hidden: true
},
{
  path: '/redirect',
  component: Layout,
  hidden: true,
  children: [{
    path: '/redirect/:path*',
    component: () => import('@/views/redirect/index')
  }]
},
{
  path: '/',
  component: Layout,
  redirect: '/home',
  children: [{
    path: 'home',
    name: 'HomeCenter',
    component: () => import('@/views/home/index'),
    meta: {
      title: '首页',
      icon: 'statistics'
    }
  }]
}
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 用户中心
  {
    path: '/users',
    component: Layout,
    redirect: '/users/index',
    name: 'UsersCenter',
    meta: {
      title: '用户中心',
      icon: 'user',
      authRules: ['users']
    },
    children: [{
      path: 'index',
      name: 'UsersManage',
      component: () => import('@/views/users/list'),
      meta: {
        title: '用户管理',
        icon: 'manage',
        authRules: ['users/index']
      }
    }
    ]
  },
  // 分馆管理
  {
    path: '/branches',
    component: Layout,
    redirect: '/branches/list',
    name: 'Activities',
    meta: {
      title: '分馆管理',
      icon: 'manage',
      authRules: ['branches']
    },
    children: [{
      path: 'list',
      name: 'BranchesManage',
      component: () => import('@/views/branches/list'),
      meta: {
        title: '分馆列表',
        icon: 'list',
        authRules: ['branches/list']
      }
    },
    {
      path: 'create',
      hidden: true,
      name: 'BranchesCreate1',
      component: () => import('@/views/branches/create'),
      meta: {
        title: '新增分馆',
        icon: 'edit',
        authRules: ['branches/create']
      }
    },
    {
      path: 'edit/:id',
      hidden: true,
      name: 'BranchesEdit1',
      component: () => import('@/views/branches/edit'),
      meta: {
        title: '编辑分馆',
        icon: 'edit',
        authRules: ['branches/edit']
      }
    },
    {
      path: 'infos',
      name: 'BranchInfosManage',
      component: () => import('@/views/branch-infos/list'),
      meta: {
        title: '分馆资讯',
        icon: 'list',
        authRules: ['branches/infos']
      }
    },
    {
      path: 'infos-create',
      hidden: true,
      name: 'BranchInfosCreate',
      component: () => import('@/views/branch-infos/create'),
      meta: {
        title: '资讯创建',
        icon: 'edit',
        authRules: ['branches/infos-create']
      }
    },
    {
      path: 'infos-edit/:id',
      hidden: true,
      name: 'BranchInfosEdit',
      component: () => import('@/views/branch-infos/edit'),
      meta: {
        title: '资讯编辑',
        icon: 'edit',
        authRules: ['branches/infos-edit']
      }
    }]
  },
  // 活动管理
  {
    path: '/activities',
    component: Layout,
    redirect: '/activities/index',
    name: 'Activities',
    meta: {
      title: '活动管理',
      icon: 'manage',
      authRules: ['activities']
    },
    children: [{
      path: 'index',
      name: 'ActivitiesManage',
      component: () => import('@/views/activities/list'),
      meta: {
        title: '活动列表',
        icon: 'list',
        authRules: ['activities/index']
      }
    },
    {
      path: 'create',
      hidden: true,
      name: 'ActivitiesCreate1',
      component: () => import('@/views/activities/create'),
      meta: {
        title: '新增活动',
        icon: 'edit',
        authRules: ['activities/create']
      }
    },
    {
      path: 'edit/:id',
      hidden: true,
      name: 'ActivitiesEdit1',
      component: () => import('@/views/activities/edit'),
      meta: {
        title: '编辑活动',
        icon: 'edit',
        authRules: ['activities/edit']
      }
    },
    {
      path: 'activity-forms',
      name: 'ActivitiesFormsManage',
      component: () => import('@/views/activity-forms/list'),
      meta: {
        title: '申请列表',
        icon: 'list',
        authRules: ['activity-forms/index']
      }
    },
    {
      path: 'activity-forms-create',
      hidden: true,
      name: 'ActivitiesFormsCreate',
      component: () => import('@/views/activity-forms/create'),
      meta: {
        title: '申请活动',
        icon: 'edit',
        authRules: ['activity-forms/create']
      }
    },
    {
      path: 'activity-forms-edit/:id',
      hidden: true,
      name: 'ActivitiesFormsEdit',
      component: () => import('@/views/activity-forms/edit'),
      meta: {
        title: '编辑申请',
        icon: 'edit',
        authRules: ['activity-forms/edit']
      }
    }]
  },
  // 志愿者活动
  {
    path: '/volunteer-activities',
    component: Layout,
    redirect: '/volunteer-activities/index',
    name: 'VolunteerActivities',
    meta: {
      title: '志愿活动',
      icon: 'example',
      authRules: ['volunteer-activities']
    },
    children: [{
      path: 'index',
      name: 'VolunteerActivitiesList',
      component: () => import('@/views/volunteer-activities/list'),
      meta: {
        title: '活动列表',
        icon: 'list',
        authRules: ['volunteer-activities/index']
      }
    },
    {
      path: 'create',
      hidden: true,
      name: 'VolunteerActivitiesCreate',
      component: () => import('@/views/volunteer-activities/create'),
      meta: {
        title: '新增活动',
        icon: 'edit',
        authRules: ['volunteer-activities/create']
      }
    },
    {
      path: 'edit/:id',
      hidden: true,
      name: 'VolunteerActivitiesEdit',
      component: () => import('@/views/volunteer-activities/edit'),
      meta: {
        title: '编辑活动',
        icon: 'edit',
        authRules: ['venues/edit']
      }
    },
    {
      path: 'forms',
      name: 'VolunteerFormsList',
      component: () => import('@/views/volunteer-forms/list'),
      meta: {
        title: '报名记录',
        icon: 'list',
        authRules: ['volunteer-forms/index']
      }
    },
    {
      path: 'forms-create',
      hidden: true,
      name: 'VolunteerFormsCreate',
      component: () => import('@/views/volunteer-forms/create'),
      meta: {
        title: '新增',
        icon: 'edit',
        authRules: ['volunteer-forms/create']
      }
    },
    {
      path: 'forms-edit/:id',
      hidden: true,
      name: 'VolunteerFormsEdit',
      component: () => import('@/views/volunteer-forms/edit'),
      meta: {
        title: '编辑',
        icon: 'edit',
        authRules: ['volunteer-forms/edit']
      }
    }
    ]
  },
  // 场馆表
  {
    path: '/venues',
    component: Layout,
    redirect: '/venues/index',
    name: 'Venues',
    meta: {
      title: '场馆列表',
      icon: 'example',
      authRules: ['venues']
    },
    children: [{
      path: 'index',
      name: 'VenuesList',
      component: () => import('@/views/venues/list'),
      meta: {
        title: '场馆列表',
        icon: 'list',
        authRules: ['venues/index']
      }
    },
    {
      path: 'create',
      hidden: true,
      name: 'VenuesCreate',
      component: () => import('@/views/venues/create'),
      meta: {
        title: '新增场馆',
        icon: 'edit',
        authRules: ['venues/create']
      }
    },
    {
      path: 'edit/:id',
      hidden: true,
      name: 'VenuesEdit',
      component: () => import('@/views/venues/edit'),
      meta: {
        title: '编辑场馆',
        icon: 'edit',
        authRules: ['venues/edit']
      }
    },
    {
      path: 'meet',
      name: 'Order',
      component: () => import('@/views/meet-orders/list'),
      meta: {
        title: '预约订单',
        icon: 'list',
        authRules: ['meet/orders']
      }
    },
    {
      path: 'orders-create',
      hidden: true,
      name: 'OrderCreate',
      component: () => import('@/views/meet-orders/create'),
      meta: {
        title: '新增订单',
        icon: 'edit',
        authRules: ['meet/orders-create']
      }
    },
    {
      path: 'orders-edit/:id',
      hidden: true,
      name: 'OrdersEdit',
      component: () => import('@/views/meet-orders/edit'),
      meta: {
        title: '编辑订单',
        icon: 'edit',
        authRules: ['meet/orders-edit']
      }
    }
    ]
  },
  // 场馆预约
  {
    path: '/meet',
    component: Layout,
    redirect: '/meet/index',
    name: 'Meet',
    hidden: true,
    meta: {
      title: '场馆预约',
      icon: 'example',
      authRules: ['meet']
    },
    children: [
      {
        path: 'persons-list',
        name: 'Persons',
        hidden: true,
        component: () => import('@/views/meet-persons/list'),
        meta: {
          title: '预约用户',
          icon: 'list',
          authRules: ['meet/persons']
        }
      },
      {
        path: 'persons-create',
        hidden: true,
        name: 'PersonCreate',
        component: () => import('@/views/meet-persons/create'),
        meta: {
          title: '新增',
          icon: 'edit',
          authRules: ['meet/persons-create']
        }
      },
      {
        path: 'persons-edit/:id',
        hidden: true,
        name: 'PersonEdit',
        component: () => import('@/views/meet-persons/edit'),
        meta: {
          title: '编辑',
          icon: 'edit',
          authRules: ['meet/persons-edit']
        }
      },
      {
        path: 'days-list',
        name: 'Days',
        hidden: true,
        component: () => import('@/views/meet-days/list'),
        meta: {
          title: '预约日期',
          icon: 'list',
          authRules: ['meet/days']
        }
      },
      {
        path: 'days-create',
        hidden: true,
        name: 'DaysCreate',
        component: () => import('@/views/meet-days/create'),
        meta: {
          title: '新增日期',
          icon: 'edit',
          authRules: ['meet/days-create']
        }
      },
      {
        path: 'days-edit/:id',
        hidden: true,
        name: 'DaysEdit',
        component: () => import('@/views/meet-days/edit'),
        meta: {
          title: '编辑日期',
          icon: 'edit',
          authRules: ['meet/days-edit']
        }
      },
      {
        path: 'meet-hours',
        hidden: true,
        name: 'Hours',
        component: () => import('@/views/meet-hours/list'),
        meta: {
          title: '预约时间',
          icon: 'list',
          authRules: ['meet/hours']
        }
      },
      {
        path: 'hours-create',
        hidden: true,
        name: 'HoursCreate',
        component: () => import('@/views/meet-hours/create'),
        meta: {
          title: '新增时间',
          icon: 'edit',
          authRules: ['meet/hours-create']
        }
      },
      {
        path: 'hours-edit/:id',
        hidden: true,
        name: 'HoursEdit',
        component: () => import('@/views/meet-hours/edit'),
        meta: {
          title: '编辑时间',
          icon: 'edit',
          authRules: ['meet/hours-edit']
        }
      }
    ]
  },
  // 非遗管理
  {
    path: '/cultural-heritage',
    component: Layout,
    redirect: '/cultural-heritage/index',
    name: 'CulturalHeritage',
    meta: {
      title: '非遗管理',
      icon: 'manage',
      authRules: ['cultural-heritage']
    },
    children: [{
      path: 'category',
      name: 'CulturalHeritageTypeManage',
      component: () => import('@/views/cultural-heritage-type/list'),
      meta: {
        title: '非遗类型',
        icon: 'list',
        authRules: ['cultural-heritage-type/index']
      }
    },
    {
      path: 'category-create',
      hidden: true,
      name: 'CulturalHeritageTypeCreate',
      component: () => import('@/views/cultural-heritage-type/create'),
      meta: {
        title: '新增非遗类型',
        icon: 'edit',
        authRules: ['cultural-heritage-type/create']
      }
    },
    {
      path: 'category-edit/:id',
      hidden: true,
      name: 'CulturalHeritageTypeEdit',
      component: () => import('@/views/cultural-heritage-type/edit'),
      meta: {
        title: '编辑非遗类型',
        icon: 'edit',
        authRules: ['cultural-heritage-type/edit']
      }
    },
    {
      path: 'index',
      name: 'CulturalHeritageManage',
      component: () => import('@/views/cultural-heritage/list'),
      meta: {
        title: '非遗列表',
        icon: 'list',
        authRules: ['cultural-heritage/index']
      }
    },
    {
      path: 'create',
      hidden: true,
      name: 'CulturalHeritageCreate',
      component: () => import('@/views/cultural-heritage/create'),
      meta: {
        title: '新增非遗项目',
        icon: 'edit',
        authRules: ['cultural-heritage/create']
      }
    },
    {
      path: 'edit/:id',
      hidden: true,
      name: 'CulturalHeritageEdit',
      component: () => import('@/views/cultural-heritage/edit'),
      meta: {
        title: '编辑非遗项目',
        icon: 'edit',
        authRules: ['cultural-heritage/edit']
      }
    }]
  },
  // 文化之声
  {
    path: '/culture-voice',
    component: Layout,
    redirect: '/culture-voice/index',
    name: 'CultureVoice',
    meta: {
      title: '文化之声',
      icon: 'example',
      authRules: ['culture-voice']
    },
    children: [{
      path: 'index',
      name: 'CultureVoiceManage',
      component: () => import('@/views/culture-voice/list'),
      meta: {
        title: '文化之声',
        icon: 'list',
        authRules: ['culture-voice/index']
      }
    },
    {
      path: 'create',
      hidden: true,
      name: 'CultureVoiceCreate',
      component: () => import('@/views/culture-voice/create'),
      meta: {
        title: '新增文化之声',
        icon: 'edit',
        authRules: ['culture-voice/create']
      }
    },
    {
      path: 'edit/:id',
      hidden: true,
      name: 'CultureVoiceEdit',
      component: () => import('@/views/culture-voice/edit'),
      meta: {
        title: '编辑文化之声',
        icon: 'edit',
        authRules: ['culture-voice/edit']
      }
    }
    ]
  },
  // 政务信息表
  {
    path: '/government-infos',
    component: Layout,
    redirect: '/government-infos/index',
    name: 'GovernmentInfos',
    meta: {
      title: '政务信息',
      icon: 'example',
      authRules: ['government-infos']
    },
    children: [{
      path: 'index',
      name: 'GovernmentInfosList',
      component: () => import('@/views/government-infos/list'),
      meta: {
        title: '政务信息',
        icon: 'list',
        authRules: ['government-infos/index']
      }
    },
    {
      path: 'create',
      hidden: true,
      name: 'GovernmentInfosCreate',
      component: () => import('@/views/government-infos/create'),
      meta: {
        title: '新增政务信息',
        icon: 'edit',
        authRules: ['government-infos/create']
      }
    },
    {
      path: 'edit/:id',
      hidden: true,
      name: 'GovernmentInfosEdit',
      component: () => import('@/views/government-infos/edit'),
      meta: {
        title: '编辑政务信息',
        icon: 'edit',
        authRules: ['government-infos/edit']
      }
    }
    ]
  },
  // 直播表
  {
    path: '/lives',
    component: Layout,
    redirect: '/lives/index',
    name: 'Lives',
    meta: {
      title: '直播管理',
      icon: 'example',
      authRules: ['lives']
    },
    children: [{
      path: 'index',
      name: 'LivesList',
      component: () => import('@/views/lives/list'),
      meta: {
        title: '直播列表',
        icon: 'list',
        authRules: ['lives/index']
      }
    },
    {
      path: 'create',
      hidden: true,
      name: 'LivesCreate',
      component: () => import('@/views/lives/create'),
      meta: {
        title: '新增直播',
        icon: 'edit',
        authRules: ['lives/create']
      }
    },
    {
      path: 'edit/:id',
      hidden: true,
      name: 'LivesEdit',
      component: () => import('@/views/lives/edit'),
      meta: {
        title: '编辑直播',
        icon: 'edit',
        authRules: ['lives/edit']
      }
    }
    ]
  },
  // 资讯表
  {
    path: '/news',
    component: Layout,
    redirect: '/news/index',
    name: 'News',
    meta: {
      title: '资讯列表',
      icon: 'example',
      authRules: ['news']
    },
    children: [{
      path: 'index',
      name: 'NewsList',
      component: () => import('@/views/news/list'),
      meta: {
        title: '资讯列表',
        icon: 'list',
        authRules: ['news/index']
      }
    },
    {
      path: 'create',
      hidden: true,
      name: 'NewsCreate',
      component: () => import('@/views/news/create'),
      meta: {
        title: '新增资讯',
        icon: 'edit',
        authRules: ['news/create']
      }
    },
    {
      path: 'edit/:id',
      hidden: true,
      name: 'NewsEdit',
      component: () => import('@/views/news/edit'),
      meta: {
        title: '编辑资讯',
        icon: 'edit',
        authRules: ['news/edit']
      }
    }
    ]
  },
  // 点播表
  {
    path: '/videos',
    component: Layout,
    redirect: '/videos/index',
    name: 'Videos',
    meta: {
      title: '点艺列表',
      icon: 'example',
      authRules: ['videos']
    },
    children: [{
      path: 'index',
      name: 'VideosList',
      component: () => import('@/views/videos/list'),
      meta: {
        title: '点艺列表',
        icon: 'list',
        authRules: ['videos/index']
      }
    },
    {
      path: 'create',
      hidden: true,
      name: 'VideosCreate',
      component: () => import('@/views/videos/create'),
      meta: {
        title: '新增点播',
        icon: 'edit',
        authRules: ['videos/create']
      }
    },
    {
      path: 'edit/:id',
      hidden: true,
      name: 'VideosEdit',
      component: () => import('@/views/videos/edit'),
      meta: {
        title: '编辑点播',
        icon: 'edit',
        authRules: ['videos/edit']
      }
    }
    ]
  },
  // 系统模块
  {
    path: '/system-module-infos',
    component: Layout,
    redirect: '/system-module-infos/index',
    name: 'SystemModuleInfos',
    meta: {
      title: '系统模块',
      icon: 'example',
      authRules: ['system-module-infos']
    },
    children: [{
      path: 'index',
      name: 'SystemModuleInfosList',
      component: () => import('@/views/system-module-infos/list'),
      meta: {
        title: '系统模块',
        icon: 'list',
        authRules: ['system-module-infos/index']
      }
    },
    {
      path: 'create',
      hidden: true,
      name: 'SystemModuleInfosCreate',
      component: () => import('@/views/system-module-infos/create'),
      meta: {
        title: '新增模块',
        icon: 'edit',
        authRules: ['system-module-infos/create']
      }
    },
    {
      path: 'edit/:id',
      hidden: true,
      name: 'SystemModuleInfosEdit',
      component: () => import('@/views/system-module-infos/edit'),
      meta: {
        title: '编辑模块',
        icon: 'edit',
        authRules: ['system-module-infos/edit']
      }
    }
    ]
  },
  // 权限管理
  {
    path: '/permission',
    component: Layout,
    redirect: '/permission/admin',
    name: 'PermissionManage',
    meta: {
      title: '权限管理',
      icon: 'user',
      authRules: ['permission']
    },
    children: [{
      path: 'admin',
      name: 'PermissionAdmin',
      component: () => import('@/views/permission/admin'),
      meta: {
        title: '管理员管理',
        icon: 'manage',
        authRules: ['permission/admin']
      }
    },
    {
      path: 'role',
      name: 'PermissionRole',
      component: () => import('@/views/permission/role'),
      meta: {
        title: '角色管理',
        icon: 'manage',
        authRules: ['permission/role']
      }
    }
    ]
  },
  // {
  //   path: '/system-configs',
  //   component: Layout,
  //   redirect: '/system-configs',
  //   name: 'systemConfigs',
  //   meta: {
  //     authRules: ['system-configs']
  //   },
  //   children: [{
  //     path: 'index',
  //     name: 'systemConfig',
  //     component: () => import('@/views/system-configs/list'),
  //     meta: {
  //       title: '系统配置',
  //       icon: 'manage',
  //       authRules: ['system-configs/index']
  //     }
  //   }]
  // },
  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
